IF OBJECT_ID('dbo.RptAgrDemographicValidataionErrorSummary') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.RptAgrDemographicValidataionErrorSummary
    IF OBJECT_ID('dbo.RptAgrDemographicValidataionErrorSummary') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.RptAgrDemographicValidataionErrorSummary >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.RptAgrDemographicValidataionErrorSummary >>>'
END
go
-- =======================================================================
-- Procedure Name: dbo.RptAgrDemographicValidataionErrorSummary
--
-- Author:      Chris Bernard, Parallax Consulting LLC
--
-- Create date: 8/09/2007
--
-- Description: Source of Report, "RptAgrDemographicValidataionErrorSummary"
--                  In Insight DB Reporting Services
--
-- Parameters:  
-- 
--              
-- Returns:     INT, 0=Success, -1=Error
--
-- SampleCall:
-- EXECUTE dbo.RptAgrDemographicValidataionErrorSummary()
--
-----------------------------------------------------------------------------------
-- Date        Initials  Modification
------------------------------------------------------------------------------------
-- 8/09/07     CB        Created
-- 1/3/2007    CB	     Added Error Description and Total Active BWH and MGH Active 
--                       cnt so % on reports could be based on Total Active Cnt
-- ==================================================================================

CREATE PROCEDURE dbo.RptAgrDemographicValidataionErrorSummary(@LogDate DATETIME)
AS
BEGIN
    -- Initial Settings
	SET NOCOUNT ON
     
    -- Declare Local Variables
    DECLARE   @Error INT,
              @RowCount INT
  
	DECLARE @TotMGHActiveCnt INT
    DECLARE @TotBWHActiveCnt INT

     SELECT @TotMGHActiveCnt=MGHActiveCnt,
            @TotBWHActiveCnt =BWHActiveCnt
       FROM dbo.Stg_AgrDemographicValidataionLog
      WHERE LogDate =@LogDate

    SELECT LogDate,TYPE,S.ErrorCode,Description AS ErrorDescription,
           Cnt,
           ActiveCnt,MGHActiveCnt,BWHActiveCnt, --This is the counts for each error
           @TotMGHActiveCnt AS TotFileMGHActiveCnt, 
           @TotBWHActiveCnt AS TotFileBWHActiveCnt
       FROM dbo.Stg_AgrDemographicValidataionErrorLog S
            INNER JOIN dbo.Stg_AdmDemographicValidationError E ON S.ErrorCode = E.ErrorCode
       WHERE LogDate =@LogDate
       ORDER BY LogDate,TYPE,S.ErrorCode
     

    SELECT @Error=@@ERROR,@RowCount=@@ROWCOUNT
    IF @Error!=0
         RETURN -1
         
    -- Return Success
    RETURN 0
     
END
go

IF OBJECT_ID('dbo.RptAgrDemographicValidataionErrorSummary') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.RptAgrDemographicValidataionErrorSummary >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.RptAgrDemographicValidataionErrorSummary >>>'
go

GRANT EXECUTE ON dbo.RptAgrDemographicValidataionErrorSummary TO InsightReport,Insight
go


